<?php require_once('../connections/con_gl.php'); ?>
<?php
$act = $_GET[act];
$url = "index.php?component=transaksiextendasuransi";

/* Validasi */
if (trim($_POST['nopolisi']) == '') {
	$error[] = '- No. Polisi harus dipilih !!!';
}

/*End validasi */
if (isset($error)) {
	echo "<b>Error</b>: <br />".implode("<br />", $error);
}else{
	if($act =='add') {
	$query = "INSERT INTO gl_transaksiextendasuransi (id, nopolisi, noref, tgltransaksi, jthtempopolis, biayapolis, nopolis, jenis, namainsurance, keterangan) VALUES (NULL,'$_POST[nopolisi]','$_POST[noref]','$_POST[tgltransaksi]','$_POST[jthtempopolis]','$_POST[biayapolis]','$_POST[nopolis]','$_POST[jenis]','$_POST[nama]','$_POST[keterangan]')";
	mysql_query("update gl_masterkendaraan set jthtempopolis='$_POST[jthtempopolis]' where nopolisi='".trim($_POST['txtnopolisi'])."'") or die (mysql_error());
	}else if($act=='edit'){
	$query ="UPDATE gl_transaksiextendasuransi SET nopolisi='$_POST[nopolisi]', noref='$_POST[noref]', tgltransaksi='$_POST[tgltransaksi]', jthtempopolis='$_POST[jthtempopolis]', biayapolis='$_POST[biayapolis]', nopolis='$_POST[nopolis]', jenis='$_POST[jenis]', namainsurance='$_POST[nama]', keterangan='$_POST[keterangan]' WHERE id='$_POST[id]'";
	mysql_query("update gl_masterkendaraan set jthtempopolis='$_POST[jthtempopolis]' where nopolisi='".trim($_POST['txtnopolisi'])."'") or die (mysql_error());
	}else{
	$query = "delete from gl_transaksiextendasuransi where id='$_POST[id]'";
	}
	mysql_select_db($database_con_gl, $con_gl);
	$runquery = mysql_query($query, $con_gl);
	if($runquery) {
		echo "<img src=\"images/ok.png\" align=\"left\" width=\"16\">&nbsp;&nbsp;Data berhasil ";if($act=='add' OR $act=='edit') { echo "disimpan";}else{ echo "dihapus"; } echo " ...";
	}else{
		echo "<img src=\"images/alert.png\" align=\"left\" width=\"16\"> Data gagal disimpan !!!";
	}
}
?>
<?php if($runquery) { ?><script type="text/javascript">setTimeout("location.href='<?php echo $url;?>'", 2000);</script><?php } ?>